import type { PiniaPluginContext } from 'pinia'
import { cloneDeep } from '@pureadmin/utils'

/**
 * The plugin reset the state of the store which is written by setup syntax
 *
 * @param context
 */
export const resetSetupStore = (context: PiniaPluginContext) => {
  const { $state } = context.store

  const defaultStore = cloneDeep($state)

  context.store.$reset = () => {
    context.store.$patch(defaultStore)
  }
}
